import hotkeys, { KeyHandler } from "hotkeys-js";
import { onMounted, onUnmounted } from "vue";

export const useHotKey = (keys: string, callback: KeyHandler) => {
  onMounted(() => {
    hotkeys(keys, callback);
  });
  onUnmounted(() => {
    hotkeys.unbind(keys, callback);
  });
};

export const bindKeys = (keys: string, callback: KeyHandler) => {
  hotkeys(keys, { keyup: true }, callback);
};

export const unbindKeys = (keys: string, callback: KeyHandler) => {
  hotkeys.unbind(keys, callback);
};
